package utils

import (
	"net"
)

func Ip() string {
	addrs, err := net.InterfaceAddrs()
	ip := "127.0.0.1"
	if err != nil {
		return ip
	}
	for _, address := range addrs {
		// 检查 ip 地址判断是否回环地址
		if ipnet, flag := address.(*net.IPNet); flag && !ipnet.IP.IsLoopback() {
			if ipnet.IP.To4() != nil {
				ip = ipnet.IP.String()
			}
		}
	}
	return ip
}
